<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: fzy-2
  Date: 2021/4/16
  Time: 20:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path = request.getContextPath(); %>
<html>
<head>
    <meta charset="utf-8">
    <title>上机考试系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- le styles -->
    <link href="<%=path%>/css/bootstrap.css" rel="stylesheet">
    <link href="<%=path%>/css/bootstrap-datetimepicker.css" rel="stylesheet">
    <link href="<%=path%>/css/exam.css" rel="stylesheet">
    <style>
        body {
            padding-top: 60px;
            /* 60px to make the container go all the way to the bottom of the topbar */
        }
    </style>
    <link href="<%=path%>/css/bootstrap-responsive.css" rel="stylesheet">

    <!-- le html5 shim, for ie6-8 support of html5 elements -->
    <!--[if lt ie 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>

<body>

<%@ include file="/WEB-INF/pages/Teacher/teacher_header.jsp"%>
<div class="container">
    <h1>
        <img src="<%=path%>/img/exam-teacher.png"  alt=""/> 上机考试管理
    </h1>


    <form class="exam-form form-inline" action="${pageContext.request.contextPath}/teacher_exam_update" method="post">
        <h4>编辑考试信息</h4>
        <% String id = request.getParameter("id");%>
        <input type="hidden" name="id" value="<%=id%>"/>
        考试名称：
        <label>
            <input type="text" name="ename" value="${exam.name}" />
        </label>
        考试时间：
        <div class="controls input-append date" id="datetimepicker" data-link-field="etime" >
            <label>
                <input class="span2" type="text" value="${exam.starttime}" readonly/>
            </label>
            <span class="add-on"><i class="icon-remove"></i></span>
            <span class="add-on"><i class="icon-th"></i></span>
        </div>
        <input type="hidden" id="etime" name="etime" value="${exam.starttime}"/>
        <div class="control-group">
            <div class="controls">
                <label class="checkbox">
                    <input type="hidden" name="eautostart" checked="checked" value="false"/>
                    <c:if test="${exam.autostart == true}">
                        <input type="checkbox" name="eautostart" checked="checked" value="true"/>
                    </c:if>
                    <c:if test="${exam.autostart == false}">
                        <input type="checkbox" name="eautostart" value="true"/>
                    </c:if>
                    自动开始
                </label>
            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <input type="submit" name="action" class="btn btn-primary" value="修改" />
            </div>
        </div>
    </form>

    <form class="exam-form form-inline" action="${pageContext.request.contextPath}/uploadServlet?id=<%=id%>&user=teacher&examname=${exam.name}" enctype="multipart/form-data" method="post">
        <c:if test="${exam.exampaper == null}">
            <h4>上传试卷</h4>
            <input type="file" name="filename" />
            <input type="submit" class="btn btn-primary" value="上传" />
        </c:if>
        <c:if test="${exam.exampaper != null}">
            <h4>试卷已上传，重复上传会导致原有文件不可用</h4>
            <input type="file" name="filename" />
            <input type="submit" class="btn btn-primary" value="更新" />
        </c:if>
    </form>

    <form class="exam-form form-inline" action="${pageContext.request.contextPath}/teacher_student" enctype="multipart/form-data" method="post">
        <h4>导入学生名单</h4>
        <p>目前设定参加此次考试的学生人数：0</p>
        <input type="file" name="filename" ><br/>
        <input type="submit" class="btn btn-primary" value="继续导入" />
    </form>

<%--    <form enctype="multipart/form-data" id="batchUpload" action="${pageContext.request.contextPath}/teacher_student" method="post" class="form-horizontal">--%>
<%--        <button class="btn btn-success btn-xs" id="uploadEventBtn" type="button" >选择文件</button>--%>
<%--        <input type="file" name="filename" style="width:0;height:0;" id="uploadEventFile">--%>
<%--        <input id="uploadEventPath"  disabled="disabled"  type="text" placeholder="请选择excel表" >--%>
<%--    </form>--%>
<%--    <button type="button" class="btn btn-success btn-sm" onclick="user.uploadBtn()">上传</button>--%>

    <form class="exam-form form-inline" action="${pageContext.request.contextPath}/teacher_exam_begin" method="">
        <h4>开启考试</h4>
        <input type="hidden" name="id" value="<%=id%>"/>
        <c:if test="${exam.exampaper == null}">
            <p class="text-warning">尚未上传试卷。</p>
        </c:if>
        <button id="btn" type="submit" class="btn btn-large"><i class="icon-off"></i> 开启</button>
    </form>
</div>
<!-- /container -->
<!-- placed at the end of the document so the pages load faster -->
<script src="<%=path%>/js/jquery.min.js"></script>
<script src="<%=path%>/js/bootstrap.min.js"></script>
<script src="<%=path%>/js/bootstrap-datetimepicker.js"></script>
<script src="<%=path%>/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script>
    let btn = $("#btn");
    let time = "${exam.starttime}";
    let starttime = new Date(time);
    let nowtime = new Date().getTime();

    let diff = nowtime - starttime;
    let m = diff/(1000*60);
    console.log(m);
    if(m > 20){
        btn.removeClass("btn-warning")
        btn.addClass("btn-danger");
        btn.attr("disabled",true);
        btn.innerText = "时间相差过久";
    }else{
        btn.removeClass("btn-danger");
        btn.addClass("btn-warning");
        btn.attr("disabled",false);
        btn.innerText = "开启";
    }

</script>
<%--<script>--%>
<%--    var MobileUser = function(){--%>

<%--        this.init = function(){--%>

<%--            //模拟上传excel--%>
<%--            $("#uploadEventBtn").unbind("click").bind("click",function(){--%>
<%--                $("#uploadEventFile").click();--%>
<%--            });--%>
<%--            $("#uploadEventFile").bind("change",function(){--%>
<%--                $("#uploadEventPath").attr("value",$("#uploadEventFile").val());--%>
<%--            });--%>

<%--        };--%>
<%--        //点击上传按钮--%>
<%--        this.uploadBtn = function(){--%>
<%--            var uploadEventFile = $("#uploadEventFile").val();--%>
<%--            if(uploadEventFile === ''){--%>
<%--                alert("请选择excel,再上传");--%>
<%--            }else if(uploadEventFile.lastIndexOf(".xls")<0){//可判断以.xls和.xlsx结尾的excel--%>
<%--                alert("只能上传Excel文件");--%>
<%--            }else{--%>
<%--                var url =  '/sign/mobile/batchImport';--%>
<%--                var formData = new FormData($('form')[6]);--%>
<%--                user.sendAjaxRequest(url,'POST',formData);--%>
<%--            }--%>
<%--        };--%>

<%--        this.sendAjaxRequest = function(url,type,data){--%>
<%--            $.ajax({--%>
<%--                url : url,--%>
<%--                type : type,--%>
<%--                data : data,--%>
<%--                success : function(result) {--%>
<%--                    let alertMsg;--%>
<%--                    alertMsg.correct( "excel上传成功");--%>
<%--                },--%>
<%--                error : function() {--%>
<%--                    let alertMsg;--%>
<%--                    alertMsg.error( "excel上传失败");--%>
<%--                },--%>
<%--                cache : false,--%>
<%--                contentType : false,--%>
<%--                processData : false--%>
<%--            });--%>
<%--        };--%>
<%--    }--%>


<%--    var user;--%>
<%--    $(function(){--%>
<%--        user = new MobileUser();--%>
<%--        user.init();--%>
<%--    });--%>
<%--</script>--%>
</body>
</html>
<script type="text/javascript">
    $("#datetimepicker").datetimepicker({
        format: "yyyy-mm-dd hh:ii",
        autoclose: true,
        todayBtn: true,
        minuteStep: 10,
        minView:0,
        pickerPosition:'bottom-left',
        language:'zh-CN'
    });
</script>
